
#include "stdafx.h"
#include "login.h"
#include "dlg_erro_msg_box.h"
#include "dll_object.h"
#include "multi_lang_impl.h"
#include <utility/common_function.h>
IMPLEMENT_DYNAMIC(dlg_erro_msg_box, CDialogBase)

dlg_erro_msg_box::dlg_erro_msg_box(CWnd* pParent /*=NULL*/)
	: CDialogBase(dlg_erro_msg_box::IDD, pParent)
{
	this->is_show_tcp_login_ = true;
}

dlg_erro_msg_box::~dlg_erro_msg_box()
{
}

void 
dlg_erro_msg_box::DoDataExchange(CDataExchange* pDX)
{
	CDialogBase::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_STATIC_LOGIN_FAILED, st_login_failed_);
	DDX_Control(pDX, IDC_ERRO_MSG, st_erro_msg_);
	DDX_Control(pDX, IDC_STATIC_NOTIFY, st_notify_msg_);
	DDX_Control(pDX, IDC_BTN_TCP_LOGIN, st_tcp_login_);
	DDX_Control(pDX, IDC_BTN_CLOSE, btn_close_);
}


BEGIN_MESSAGE_MAP(dlg_erro_msg_box, CDialogBase)
	ON_BN_CLICKED(IDC_BTN_CLOSE, &dlg_erro_msg_box::OnBnClickedBtnClose)
	ON_BN_CLICKED(IDC_BTN_TCP_LOGIN, &dlg_erro_msg_box::OnBnClickedBtnTcpLogin)
END_MESSAGE_MAP()

BOOL 
dlg_erro_msg_box::OnInitDialog()
{
	CDialogBase::OnInitDialog();
	SetDpi(IDD);

	dsSkinWindow(GetSafeHwnd(), SKIN_TYPE_DIALOG, "login.dlg.erro_msgbox", TRUE);
	dsSkinWindow(GetDlgItem(IDC_STATIC_LOGIN_FAILED)->m_hWnd, SKIN_TYPE_STATIC, "static12_blod", FALSE);
	dsSkinWindow(GetDlgItem(IDC_BTN_TCP_LOGIN)->m_hWnd, SKIN_TYPE_STATIC, "linkstatic", FALSE);

	change_language();
	this->st_erro_msg_.SetWindowText(this->erro_text_);
	change_wnd_pos();
	SetWindowPos(CWnd::FromHandle(HWND_TOPMOST), 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
	return TRUE;  

}
void 
dlg_erro_msg_box::set_notify_text(CString text, BOOL is_show_tcp_login)
{
	this->erro_text_ = text;
	this->is_show_tcp_login_ = is_show_tcp_login;
}

void dlg_erro_msg_box::OnBnClickedBtnClose()
{
	OnOK();
}


void 
dlg_erro_msg_box::change_language()
{
	g_multi_lang_impl.change_language(m_hWnd, IDD);
}

void 
dlg_erro_msg_box::change_wnd_pos()
{
	if ( this->is_show_tcp_login_ )
	{
		this->st_tcp_login_.ShowWindow(SW_SHOW);
		this->st_notify_msg_.ShowWindow(SW_SHOW);
		CRect rc;
		GetWindowRect(rc);
		rc.bottom = rc.bottom + 50;
		MoveWindow(rc);

		set_pos_down_to(this->st_erro_msg_, this->st_notify_msg_, 0, 0);
		set_pos_down_to(this->st_notify_msg_, this->st_tcp_login_, 0 ,0);
		ScreenToClient(rc);
		set_wnd_pos(this->btn_close_, rc.right - 72, rc.bottom - 27);
	}
}

void dlg_erro_msg_box::OnBnClickedBtnTcpLogin()
{
	g_dll_obj->is_login_by_tcp_ = TRUE;
	OnOK();
}